package cases.chapter08.chapter0804;

class Bricks implements Runnable {
    private int time = 0;

    public void run() {
        if (Thread.currentThread().getName().equals("张三")) {
            zsmovebrick();    //计算张三搬砖所用时间的方法
        } else if (Thread.currentThread().getName().equals("李四")) {
            lsmovebrick();    //计算李四搬砖所用时间的方法
        }
    }

    private synchronized void zsmovebrick() {
        time = (int) Math.ceil((double) 100 / (double) 3) * 10;
        System.out.println(Thread.currentThread().getName() + "搬完100块砖需" +
                "要" + time + "分钟");
    }

    private synchronized void lsmovebrick() {
        time = 100 / 5 * 12;
        System.out.println(Thread.currentThread().getName() + "搬完100块砖需" +
                "要" + time + "分钟");
    }
}

public class MoveBricks {
    public static void main(String[] args) {
        Bricks bricks = new Bricks();
        new Thread(bricks, "张三").start();
        new Thread(bricks, "李四").start();
    }
}